using System;
namespace Microsoft.Expression.Drawing.Core
{
	internal class RandomEngine
	{
		private Random random;
		private double? anotherSample;
		public RandomEngine(long seed)
		{
			this.Initialize(seed);
		}
		public double NextGaussian(double mean, double variance)
		{
			return this.Gaussian() * variance + mean;
		}
		public double NextUniform(double min, double max)
		{
			return this.Uniform() * (max - min) + min;
		}
		private void Initialize(long seed)
		{
			this.random = new Random((int)seed);
		}
		private double Uniform()
		{
			return this.random.NextDouble();
		}
		private double Gaussian()
		{
			if (this.anotherSample.get_HasValue())
			{
				double value = this.anotherSample.get_Value();
				this.anotherSample = default(double?);
				return value;
			}
			double num;
			double num2;
			double num3;
			do
			{
				num = 2.0 * this.Uniform() - 1.0;
				num2 = 2.0 * this.Uniform() - 1.0;
				num3 = num * num + num2 * num2;
			}
			while (num3 >= 1.0);
			double num4 = Math.Sqrt(-2.0 * Math.Log(num3) / num3);
			this.anotherSample = new double?(num * num4);
			return num2 * num4;
		}
	}
}
